package com.xxchat.entity.enums;

import com.xxchat.utils.StringTools;
import lombok.Getter;

/**
 * @author Waicc
 */

@Getter
public enum JoinTypeEnum {
    JOIN(0, "不需要同意"),
    APPLY(1, "需要同意");

    private Integer type;
    private String desc;

    JoinTypeEnum(Integer code, String desc) {
        this.type = code;
        this.desc = desc;
    }

    public static JoinTypeEnum getByName(String name){
        try {
            if (StringTools.isEmpty(name)) {
                return null;
            }
            return JoinTypeEnum.valueOf(name.toUpperCase());
        } catch (Exception e) {
            return null;
        }
    }

    public static JoinTypeEnum getByType(Integer type){
        for (JoinTypeEnum joinTypeEnum : JoinTypeEnum.values()) {
            if (joinTypeEnum.getType().equals(type)) {
                return joinTypeEnum;
            }
        }
        return null;
    }
}
